#ifndef IMAGECOORDINATEGEOMETRY_H
#define IMAGECOORDINATEGEOMETRY_H

#include "GuidedNativeImageIO.h"

#include <QVector>
#include <QString>
#include <QMessageBox>

#include "vtkMath.h"
#include "vtkMatrix3x3.h"
#include "vtkMatrix4x4.h"
#include "vtkVector.h"
#include "vtkSmartPointer.h"

class ImageProperties;

class ImageCoordinateGeometry
{
public:
    typedef vtkSmartPointer<vtkMatrix3x3> DirectionMatrixPointer;
    typedef vtkSmartPointer<vtkMatrix4x4> TransformMatrixPointer;
    typedef vtkMatrix4x4 TransformMatrixType;

    ImageCoordinateGeometry(ImageProperties &imageProperies);
    ImageCoordinateGeometry() {}
    ~ImageCoordinateGeometry() {}

    bool IsOblique()
    { return m_IsOblique; }

    TransformMatrixType *GetAxialMatrix()
    { return m_AxialTransformMatrix.GetPointer(); }

    double* GetITKWorldPoint(double *VTKpoint, double *ITKPoint);

//    void GetSaggitalMatrix();
//    void GetCoronalMatrix();

    QString GetLPSCode()
    { return m_LPSCode; }

private:
    void ConvertOrientationToVTKMatrix(QVector<double> orientationX,
                                       QVector<double> orientationY);
    bool IsDirectionMatrixOblique();

    void ConvertToAxialMatrix();
    void SetDefaultTransformMatrices();
    void CalculateTransformMatrices();

    QString DetermineClosestLPSCode(DirectionMatrixPointer directionMatrix);

    QString m_LPSCode;
    QVector<double> m_ImagePosition;
    bool m_IsOblique;

    DirectionMatrixPointer m_DirectionMatrix;
    DirectionMatrixPointer m_InvertedDirectionMatrix;

    TransformMatrixPointer m_AxialTransformMatrix;
    TransformMatrixPointer m_SaggitalTransformMatrix;
    TransformMatrixPointer m_CoronalTransformMatrix;
};

#endif
